package com.wanxi.servlet;

import com.wanxi.model.Brand;
import com.wanxi.service.BrandService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findById")
public class FindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //        1.乱码处理
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
//        2.得到前端的值
        String id=req.getParameter("id");
//        String brandName = req.getParameter("brandName");
//        String enterPriseName = req.getParameter("enterPriseName");
//        String sort = req.getParameter("sort");
//        String brandIntroduce = req.getParameter("brandIntroduce");
//        String enable = req.getParameter("enable");
//        3.将数据封装成对象
        Brand brand = Brand.builder()
                .id(Tool.strToInt(id))
                .build();
//        4.根据id在dao的数据里面查询
        BrandService brandService = new BrandService();
        Brand model = brandService.findById(brand);
        req.setAttribute("model", model);
        req.getRequestDispatcher("/update.jsp").forward(req, resp);
    }
}
